/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.classes;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.cassandra.CassandraAccess;
import org.w3c.dom.Element;

/**
 *
 * @author marc
 */
public class Join extends Activity{

    private String time;
    private String user;
    private String cidName;
    private String cidNumber;
    private boolean muted;
    private boolean talking;

    public static final String JOIN_ACTIVITY="join";

    public static final String ATTRIB_TIME="time";
    public static final String ATTRIB_USER="user";
    public static final String ATTRIB_CIDNAME="cidName";
    public static final String ATTRIB_CIDNUMBER="cidNumber";
    public static final String ATTRIB_MUTED="muted";
    public static final String ATTRIB_TALKING="talking";

    public Join(String time, String user, String cidName, String cidNumber, boolean muted, boolean talking) {
        this.type = JOIN_ACTIVITY;
        this.time = time;
        this.user = user;
        this.cidName = cidName;
        this.cidNumber = cidNumber;
        this.muted = muted;
        this.talking = talking;
    }

    public Join(){
        this.type = JOIN_ACTIVITY;
    }
    
    public String save(){
        String resp="";

        CassandraAccess ca=new CassandraAccess(CommonUtils.URL_DATABASE, CommonUtils.PORT_DATABASE, CommonUtils.BBBCONFERENCE_KEYSPACE);
        try {
            java.util.UUID timeuuid=CommonUtils.getTimeUUID();
            resp += ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString(), ATTRIB_TYPE.getBytes("UTF-8"), this.type);
            resp += ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString(), ATTRIB_TIME.getBytes("UTF-8"), this.time);
            resp += ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString(), ATTRIB_USER.getBytes("UTF-8"), this.user);
            resp+=ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString() ,ATTRIB_CIDNUMBER.getBytes("UTF-8"), this.cidNumber);
            resp+=ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString() ,ATTRIB_CIDNAME.getBytes("UTF-8"), this.cidName);
            resp+=ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString() ,ATTRIB_MUTED.getBytes("UTF-8"), new Boolean(this.muted).toString());
            resp+=ca.insertValue(CFNAME, CommonUtils.asByteArray(timeuuid),this.bbbconference.getUuid().toString() ,ATTRIB_TALKING.getBytes("UTF-8"), new Boolean(this.talking).toString());
        } catch (Exception ex) {
            Logger.getLogger(Join.class.getName()).log(Level.SEVERE, null, ex);
        }
        ca.closePoolCassandra();
        return resp;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @return the cidName
     */
    public String getCidName() {
        return cidName;
    }

    /**
     * @param cidName the cidName to set
     */
    public void setCidName(String cidName) {
        this.cidName = cidName;
    }

    /**
     * @return the cidNumber
     */
    public String getCidNumber() {
        return cidNumber;
    }

    /**
     * @param cidNumber the cidNumber to set
     */
    public void setCidNumber(String cidNumber) {
        this.cidNumber = cidNumber;
    }

    /**
     * @return the muted
     */
    public boolean isMuted() {
        return muted;
    }

    /**
     * @param muted the muted to set
     */
    public void setMuted(boolean muted) {
        this.muted = muted;
    }

    /**
     * @return the talking
     */
    public boolean isTalking() {
        return talking;
    }

    /**
     * @param talking the talking to set
     */
    public void setTalking(boolean talking) {
        this.talking = talking;
    }

    /**
     * @return the time
     */
    public String getTime() {
        return time;
    }

    /**
     * @param time the time to set
     */
    public void setTime(String time) {
        this.time = time;
    }
}
